package com.daxt.controller.filemanager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Consumer;

import com.daxt.common.annotations.LoginAuth;
import com.daxt.common.annotations.LoginUser;
import com.daxt.common.annotations.OperLog;
import com.daxt.common.util.DateUtil;
import com.daxt.mapper.archives.ArchivesDocMapper;
import com.daxt.mapper.sys.ArchivesClassMapper;
import com.daxt.mapper.sys.RoleMapper;
import com.daxt.mapper.sys.UserRoleMapper;
import com.daxt.model.constant.FileExt;
import com.daxt.model.dic.BehaveLogType;
import com.daxt.model.dic.DicDocState;
import com.daxt.model.dic.SystemConfigType;
import com.daxt.model.dic.VersionsMarkType;
import com.daxt.model.dto.BaseQueryDto;
import com.daxt.model.service.archives.param.DirectMount;
import com.daxt.model.service.archives.vo.ArchivesBehaveLog;
import com.daxt.model.service.archives.vo.ArchivesDoc;
import com.daxt.model.service.base.result.UserInfo;
import com.daxt.model.service.base.vo.Role;
import com.daxt.model.service.base.vo.UserRole;
import com.daxt.service.ArchivesBehaveLogService;
import com.daxt.utils.ArchivesUtil;
import com.daxt.utils.BaseUtil;
import com.daxt.utils.WordUtil;
import com.daxt.utils.file.FileBaseUtil;
import com.daxt.utils.file.PdfUtils;
import com.daxt.utils.file.ToPdfUtil;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.daxt.base.common.util.RedisUtil;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.archives.ArchivesDocFileMapper;
import com.daxt.mapper.sys.ArchivesTypeMapper;
import com.daxt.model.service.archives.param.MountBathch;
import com.daxt.model.service.archives.vo.ArchivesDocFile;
import com.daxt.model.service.archives.vo.ArchivesType;
import com.daxt.service.MountService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Flux;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "文件挂接")
@RestController
@RequestMapping("/fileManager")
public class MountController {

    @Autowired
    private ArchivesDocFileMapper archivesDocFileMapper;
    @Autowired
    private MountService mountService;
    @Autowired
    private ArchivesTypeMapper archivesTypeMapper;
    @Autowired
    private ArchivesClassMapper archivesClassMapper;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ArchivesDocMapper archivesDocMapper;
    @Autowired
    private ArchivesBehaveLogService archivesBehaveLogService;

    @Autowired
    private RoleMapper roleMapper;

//	@Value(value = "${systemConfig.tempPath}")
//	private String basePath11;
@Autowired
private UserRoleMapper userRoleMapper;


    @ApiOperation(value = "挂接文件列表", notes = "")
    @GetMapping("/mount/{docId}")
    public Result<List<ArchivesDocFile>> mountFile(@PathVariable("docId") String docId
                            ,@ApiParam("用户id") @RequestParam(value = "userId",required = false) String userId) {

        //获取普通用户角色的id
        List<Long> roleIds=getPuTongId();

        int count=0;
        if(roleIds.size()>0){
            QueryWrapper<UserRole> userRoleQueryWrapper=new QueryWrapper<>();
            userRoleQueryWrapper.in("roleId",roleIds);
            userRoleQueryWrapper.eq("userId",userId);
            count=userRoleMapper.selectCount(userRoleQueryWrapper);
        }


        List<String> notInExt = new ArrayList<>();
        //notInExt.add("doc");
        //notInExt.add("docx");
        notInExt.add("xlsx");
        notInExt.add("xls");

        QueryWrapper<ArchivesDocFile> queryWrapper = new QueryWrapper<ArchivesDocFile>();
        queryWrapper.eq("docId", docId);
        queryWrapper.notIn("extName",notInExt);
//        queryWrapper.eq("extName", "pdf");

        //普通用户权限，只能查看自己上传的附件
        if(RedisUtil.isAppoint(VersionsMarkType.VERSIONS_5)) {
            if (count > 0 && !StringUtils.isEmpty(userId)) {
                queryWrapper.and(i -> i.eq("userid", userId)
                        .or().eq("userid", "")
                        .or().isNull("userid")
                );
            }
        }

        List<ArchivesDocFile> list = archivesDocFileMapper.selectList(queryWrapper);
//        for (int i = 0; i < list.size(); i++) {
//            list.get(i).setFileUrl(SystemConfig.showOssFile + list.get(i).getFileUrl());
//        }
        return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "", list);
    }

    /**
     * @description:
     * @author: lig
     * @date: 2021/7/22
     */
    @ApiOperation(value = "查看挂接文件列表通过卷号", notes = "")
    @GetMapping("/mount/list/{dessierId}")
    public Result<List<ArchivesDocFile>> showFile(@PathVariable("dessierId") String dossierId,
                                                  @ApiParam("用户id") @RequestParam(value = "userId",required = false) String userId) {

        QueryWrapper<ArchivesDoc> queryWrapper = new QueryWrapper<ArchivesDoc>();
        queryWrapper.eq("dossierId", dossierId);
        List<ArchivesDoc> list = archivesDocMapper.selectList(queryWrapper);


        List<Long> roleIds=getPuTongId();
        int count=0;
        if(roleIds.size()>0){
            QueryWrapper<UserRole> userRoleQueryWrapper=new QueryWrapper<>();
            userRoleQueryWrapper.in("roleId",roleIds);
            userRoleQueryWrapper.eq("userId",userId);
            count=userRoleMapper.selectCount(userRoleQueryWrapper);
        }

        List<ArchivesDocFile> resultList = new ArrayList<ArchivesDocFile>();
        for (ArchivesDoc ad : list) {
            QueryWrapper<ArchivesDocFile> qwFile = new QueryWrapper<ArchivesDocFile>();
            qwFile.eq("docId", ad.getId());
            //普通用户权限，只能查看自己上传的附件
            if(RedisUtil.isAppoint(VersionsMarkType.VERSIONS_5)) {
                if (count > 0 && !StringUtils.isEmpty(userId)) {
                    qwFile.and(i -> i.eq("userid", userId)
                            .or().eq("userid", "")
                            .or().isNull("userid")
                    );
                }
            }

            List<ArchivesDocFile> adFileList = new ArrayList<ArchivesDocFile>();
            adFileList = archivesDocFileMapper.selectList(qwFile);
            for (int i = 0; i < adFileList.size(); i++) {
//                adFileList.get(i).setFileUrl(SystemConfig.showOssFile + adFileList.get(i).getFileUrl());
                adFileList.get(i).setFileUrl(adFileList.get(i).getFileUrl());
                adFileList.get(i).setItemNum(ad.getItemNum());
            }

            resultList.addAll(adFileList);
        }

        return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "", resultList);
    }


    @ApiOperation(value = "挂接文件", notes = "")
    @PostMapping("/mount")
    @OperLog(operModul = "挂接文件", operType = "ADD", operDesc = "新日志")
    @LoginAuth()
    @Transactional(rollbackFor = Exception.class)
    public Result<String> mountFile(@ApiIgnore @LoginUser UserInfo loginUser,
                                    @RequestBody ArchivesDocFile archivesDocFile,
                                    HttpServletRequest request) {
        Result<String> mountFile = mountService.mountFile(archivesDocFile);

        if(RedisUtil.isAppoint(VersionsMarkType.VERSIONS_5)) {
            if(ResultCode.RESULT_SUCCESS.getCode().equals(mountFile.getCode())){
                 ArchivesDoc doc= archivesDocMapper.selectById(archivesDocFile.getDocId());
                 if("doc".equals(doc.getFileType()) && doc.getDossierId()!=0) {
                     ArchivesDoc doss= archivesDocMapper.selectById(doc.getDossierId());
                     if("4".equals(doss.getDocFrom())){
                         doss.setDocFrom("6");
                         archivesDocMapper.updateById(doss);
                     }
                 }
                 if("doc".equals(doc.getFileType()) && doc.getDossierId() ==0) {
                     if("4".equals(doc.getDocFrom())){
                         doc.setDocFrom("6");
                         archivesDocMapper.updateById(doc);
                     }
                 }
            }
        }
        if(ResultCode.RESULT_SUCCESS.getCode().equals(mountFile.getCode())){
            archivesBehaveLogService.saveArchivesBehaveLog(new ArchivesBehaveLog(archivesDocFile.getDocId().toString(), BehaveLogType.ONE_MOUNT.getKey(),BehaveLogType.ONE_MOUNT.getValue(),null),loginUser ,request);
        }
        return mountFile;
    }


    @ApiOperation(value = "上传文件", notes = "")
    @PostMapping("/mount/update")
    @OperLog(operModul = "上传文件", operType = "ADD", operDesc = "新日志")
    public Result<String> mountUpdateFile(@ApiParam("卷dossier 件doc") @RequestParam(value = "fileType") String fileType
            ,@ApiParam("门类id") @RequestParam(value = "typeId") String typeId
            ,@ApiParam("分类id") @RequestParam(value = "classId",required = false) String classId
            ,@ApiParam("state状态") @RequestParam(value = "state") String state
            ,@ApiParam("全宗id") @RequestParam(value = "fondsId") String fondsId
            ,@ApiParam("dossierId") @RequestParam(value = "dossierId",required = false) String dossierId
            ,@RequestBody ArchivesDocFile archivesDocFile) {

        if(!archivesDocFile.getIsRealName()){
            return ResultUtil.error("1001","必须使用真实名称");
        }
        if(StringUtils.isEmpty(archivesDocFile.getFileName())){
            return ResultUtil.error("1001","文件名称不能为空");
        }

        String ossDir = RedisUtil.getSysConfig(SystemConfigType.OSS_DIR);
        String tempPath = RedisUtil.getSysConfig(SystemConfigType.TEMP_PATH);

        String fileName= archivesDocFile.getFileName();
        String ext=FileBaseUtil.getFileNameExt(fileName);
        String fileUrl=archivesDocFile.getFileUrl();

        String fileTitle=IdWorker.getIdStr();

        File downFile = new File(ossDir + fileUrl);

        int pages=0;

        if(ext.equalsIgnoreCase(FileExt.pdf.getDesc())){  //pdf
            //统计页数
            pages= PdfUtils.getPdfPageCount(downFile.getAbsolutePath());

        }else if (ext.equalsIgnoreCase(FileExt.doc.getDesc()) || ext.equalsIgnoreCase(FileExt.docx.getDesc())) { // word
            String pdfPath=tempPath+"/"+fileTitle+".pdf";
            ToPdfUtil.doc2pdf(downFile.getAbsolutePath(), pdfPath);

            pages= PdfUtils.getPdfPageCount(pdfPath);

        } else if (ext.equalsIgnoreCase(FileExt.xls.getDesc()) || ext.equalsIgnoreCase(FileExt.xlsx.getDesc())) { // excel格式附件
            String pdfPath=tempPath+"/"+fileTitle+".pdf";
            ToPdfUtil.excel2pdf(downFile.getAbsolutePath(), pdfPath);

            pages= PdfUtils.getPdfPageCount(pdfPath);

        } else if (ext.equalsIgnoreCase(FileExt.img_jpg.getDesc()) || ext.equalsIgnoreCase(FileExt.img_png.getDesc())
                || ext.equalsIgnoreCase(FileExt.img_tif.getDesc()) || ext.equalsIgnoreCase(FileExt.img_tiff.getDesc())
                || ext.equalsIgnoreCase(FileExt.img_jpeg.getDesc()) || ext.equalsIgnoreCase(FileExt.img_gif.getDesc())){ // jpg、png、tif、jpeg、gif格式附件
            String pdfPath=tempPath+"/"+fileTitle+".pdf";
            PdfUtils.oneImgToPdf(downFile.getAbsolutePath(), pdfPath);

            pages= PdfUtils.getPdfPageCount(pdfPath);

        }


        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);


        String title=archivesDocFile.getFileName().substring(0,archivesDocFile.getFileName().lastIndexOf("."));


        if("doc".equals(fileType)){//件
            //或当前分类下，案件和案卷的最大件号和卷号
            ArchivesType at=archivesTypeMapper.selectById(Long.parseLong(typeId));
            if (StringUtils.isEmpty(at.getGenItemNum())){
                return ResultUtil.error("1001","请配置案件号的生成规则！");
            }
            QueryWrapper<ArchivesDoc> maxWrapper = new QueryWrapper<ArchivesDoc>();
            maxWrapper.eq("typeId",typeId);
            maxWrapper.eq("classId",classId);
            maxWrapper.eq("isDelete",0);
            maxWrapper.eq("fondsId",fondsId);
            List<String> states=new ArrayList<>();
            states.add("0");
            states.add("1");
            states.add("2");
            maxWrapper.in("state", states);
            maxWrapper.eq("char_length(itemNum)",at.getGenItemNum());
            maxWrapper.select("max(itemNum) as itemNum");
            ArchivesDoc archivesDocMax = archivesDocMapper.selectOne(maxWrapper);
            int maxItemNum=0;
            if(archivesDocMax!=null){
                maxItemNum=Integer.parseInt(archivesDocMax.getItemNum());
            }
            maxItemNum++;
            String itemNum=maxItemNum+"";

            ArchivesDoc archivesDoc=new ArchivesDoc();
            archivesDoc.setFileType("doc");
            archivesDoc.setTitle(title);
            archivesDoc.setState(state);
            archivesDoc.setClassId(Long.parseLong(classId));
            archivesDoc.setTypeId(Long.parseLong(typeId));
            archivesDoc.setDossierId(0L);
            archivesDoc.setCreateTime(LocalDateTime.now());
            archivesDoc.setArchivalYear(year+"");
            if(pages!=0){
                archivesDoc.setPages(pages+"");
            }
            archivesDoc.setDocFrom("3");

            //件号处理
            int genItemNum = Integer.parseInt(at.getGenItemNum());
            if (itemNum.length()<genItemNum){
                int count=genItemNum-itemNum.length();
                for (int i=0;i<count;i++){
                    itemNum="0"+itemNum;
                }
            }
            archivesDoc.setItemNum(itemNum);
            archivesDoc.setFondsId(fondsId);

            archivesDocMapper.insert(archivesDoc);

            archivesDocFile.setDocId(archivesDoc.getId());

        }else if("dossier".equals(fileType)){
            if(StringUtils.isEmpty(dossierId)){//散文件
                ArchivesDoc archivesDoc=new ArchivesDoc();
                archivesDoc.setFileType("scattered");
                archivesDoc.setTitle(title);
                archivesDoc.setState(state);
                archivesDoc.setDossierId(0L);
                if(!StringUtils.isEmpty(classId)){
                    archivesDoc.setClassId(Long.parseLong(classId));
                }
                archivesDoc.setTypeId(Long.parseLong(typeId));
                archivesDoc.setFondsId(fondsId);
                archivesDoc.setCreateTime(LocalDateTime.now());
                archivesDoc.setDocFrom("3");
                archivesDoc.setArchivalYear(year+"");
                if(pages!=0){
                    archivesDoc.setPages(pages+"");
                }

                archivesDocMapper.insert(archivesDoc);
                archivesDocFile.setDocId(archivesDoc.getId());
            }else{//卷内文件
                ArchivesDoc dossier = archivesDocMapper.selectById(dossierId);

                QueryWrapper<ArchivesDoc> maxDoc=new QueryWrapper<>();
                maxDoc.select("max(itemNum) itemNum");
                maxDoc.eq("dossierId",dossierId);
                ArchivesDoc maxArchivesDoc = archivesDocMapper.selectOne(maxDoc);
                int maxItemNum=0;
                String itemNum="";
                if(maxArchivesDoc!=null){
                    //System.out.println("进来了！！！");
                    maxItemNum=Integer.parseInt(maxArchivesDoc.getItemNum());
                    maxItemNum++;
                    itemNum=maxItemNum+"";
                    int length=maxArchivesDoc.getItemNum().length();
                    for (int i=0;i<length-itemNum.length();i++){
                        itemNum="0"+itemNum;
                    }
                }else {
                    itemNum="01";
                }

                ArchivesDoc archivesDoc=new ArchivesDoc();
                archivesDoc.setFileType("doc");
                archivesDoc.setTitle(title);
                archivesDoc.setState(dossier.getState());
                if(!StringUtils.isEmpty(classId)){
                    archivesDoc.setClassId(dossier.getClassId());
                }
                archivesDoc.setTypeId(dossier.getTypeId());
                archivesDoc.setDossierNum(dossier.getDossierNum());
                archivesDoc.setCreateTime(LocalDateTime.now());;//
                archivesDoc.setArchivalNum(dossier.getArchivalNum());
                archivesDoc.setFondsId(dossier.getFondsId());
                archivesDoc.setItemNum(itemNum);
                archivesDoc.setDossierId(dossier.getId());
                archivesDoc.setDocFrom("3");
                archivesDoc.setArchivalYear(year+"");
                if(pages!=0){
                    String dossPages=dossier.getPages();
                    int dossPagesInt=0;
                    if(!StringUtils.isEmpty(dossPages)){
                        dossPagesInt= Integer.parseInt(dossPages);
                    }
                    dossPagesInt=dossPagesInt+pages;
                    dossier.setPages(dossPagesInt+"");
                    archivesDocMapper.updateById(dossier);

                    archivesDoc.setPages(pages+"");
                }

                archivesDocMapper.insert(archivesDoc);

                archivesDocFile.setDocId(archivesDoc.getId());
            }

        }


        if("doc".equals(fileType)||("dossier".equals(fileType)&&!StringUtils.isEmpty(dossierId))){
            archivesDocFile.setIsRealName(false);
            archivesDocFile.setFileName(null);
        }

        Result<String> mountFile = mountService.mountFile(archivesDocFile);
        return mountFile;
    }

    @ApiOperation(value = "批量挂接文件", notes = "")
    @PostMapping("/mount/batch")
    @OperLog(operModul = "批量挂接文件", operType = "ADD", operDesc = "新日志")
    @LoginAuth()
    public Result<String> mountBatchFile(@ApiIgnore @LoginUser UserInfo loginUser,
                                         @RequestBody MountBathch mountBathch,
                                         HttpServletRequest request) throws Exception {
        if (mountBathch.getIds() == null || mountBathch.getIds().size() == 0) {
            return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), "请选择批量挂接的卷或件！！！", null);
        }
        String taskId = IdWorker.getIdStr();

        QueryWrapper<ArchivesType> queryWrapper = ArchivesUtil.builBaseQueryWrapper(new BaseQueryDto(mountBathch.getFondsId(),mountBathch.getTypeNum()));
        List<ArchivesType> selectList = archivesTypeMapper.selectList(queryWrapper);
        if (selectList != null && selectList.size() > 0) {
            redisUtil.set(taskId, "0", 60 * 60 * 3);
            mountService.mountBatchFile(mountBathch, taskId, selectList.get(0));

            archivesBehaveLogService.saveArchivesBehaveLog(new ArchivesBehaveLog(BaseUtil.listToString(mountBathch.getIds()),BehaveLogType.BATCH_MOUNT.getKey(),BehaveLogType.BATCH_MOUNT.getValue(),null),loginUser ,request);
            return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "开始挂接...", taskId);
        } else {
            return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), "全宗号或门类号异常", null);
        }
    }

    @ApiOperation(value = "批量挂接文件结果", notes = "")
    @PostMapping("/mount/batch/{resultId}")
    public Result<String> mountBatchFile(@ApiParam("0进行中 1完成 2失败") @PathVariable("resultId") String resultId) throws Exception {
        String result = (String) redisUtil.get(resultId);
        if (result.startsWith("1") && result.contains(":")) {
            String[] split = result.split(":");

            return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "成功挂接" + split[1] + "个文件", split[0]);
        } else if (result.startsWith("3") && result.contains(":")) {
            String[] split = result.split(":");
            return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), split[1], null);
        }

        return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "挂接失败！！！", StringUtils.isEmpty(result) ? "2" : result);
    }



    @ApiOperation(value = "扫描挂接文件", notes = "")
    @PostMapping("/mountWiaacmgr/{docId}")
//    @OperLog(operModul = "扫描挂接文件", operType = "ADD", operDesc = "新日志")
    public String MountWiaacmgrFile(@ApiParam("件ID") @PathVariable("docId") String docId
                                    ,@RequestParam(value = "typeId", required = false) String typeId
                                    ,@RequestParam(value = "userId", required = false) String userId
                                    ,@RequestParam("RemoteFile") MultipartFile file) {
        ArchivesDoc aDoc = archivesDocMapper.selectById(docId);

        try {

            String fileName=file.getOriginalFilename();
            if(fileName.contains(".pdf")){
                Result<String> mountFile = mountService.MountWiaacmgrFile(aDoc, file,null,userId);
                return mountFile.getMsg();
            }else{
                String ossDir = RedisUtil.getSysConfig(SystemConfigType.OSS_DIR);
                int lastIndexOf = file.getOriginalFilename().lastIndexOf(".");
                String substring = file.getOriginalFilename().substring(lastIndexOf);
                String type=typeId+"/file";

                String objectName=type + "/" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM")) + "/" + UUID.randomUUID() + substring;
                InputStream inputStream = file.getInputStream();
                File tempFile =new File(ossDir+"/temp/"+objectName);
                FileUtils.copyToFile(inputStream,tempFile);

                String tempPath2 = tempFile.getAbsolutePath().replaceAll("\\\\","/");
                String outPdf = tempPath2.substring(0, tempPath2.lastIndexOf("."));
                PdfUtils.oneImgToPdf(tempFile.getAbsolutePath(), outPdf+".pdf");
                File saveFile= new File(outPdf+".pdf");

                Result<String> mountFile = mountService.MountWiaacmgrFile(aDoc, file,saveFile,userId);
                return mountFile.getMsg();
            }
        }catch (IOException io){
            io.printStackTrace();
        }
        return "1000";

    }


    @ApiOperation(value = "直接挂接文件（zip）（内蒙）", notes = "")
    @PostMapping("/directMount")
    @OperLog(operModul = "直接挂接文件", operType = "ADD", operDesc = "新日志")
    public Result<String> directMount(@RequestBody DirectMount directmount) {
        return mountService.directMountFile(directmount);
    }


    private List<Long> getPuTongId(){
        QueryWrapper<Role> roleQueryWrapper=new QueryWrapper<>();
        roleQueryWrapper.like("name","普通用户");
        List<Role> roles= roleMapper.selectList(roleQueryWrapper);
        List<Long> roleIds=new ArrayList<>();
        for(int i=0;i<roles.size();i++){
            roleIds.add(roles.get(i).getId());
        }
        return roleIds;
    }


//	public static String getContentType(String fileUrl) {
//        String contentType = null;
//        try {
//            contentType = new MimetypesFileTypeMap().getContentType(new File(fileUrl));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return contentType;
//    }
//
//	public void deleteFolder(File[] file) {
//		for (File tempfile : file) {
//			if(tempfile.isDirectory()) {
//				File[] listFiles = tempfile.listFiles();
//				if(listFiles.length>0) {
//					deleteFolder(listFiles);
//					tempfile.delete();
//			}else {
//				tempfile.delete();
//			}
//			}else {
//				tempfile.delete();
//			}
//		}
//	}
}
